package GUI.Admin;

import GUI.System.GUIFrame;
import java.util.ArrayList;
import javax.swing.JOptionPane;

/**
 * Panel for detailed administrator view of a billing.
 */
public class TransactHisBillingDetailsAdminPanel extends javax.swing.JPanel {

    private GUIFrame frame;

    /**
     * Custom constructor.
     */
    public TransactHisBillingDetailsAdminPanel() {
        initComponents();
    }

    /**
     * Setter for GUIFrame reference.
     *
     * @param frame GUIFrame object.
     */
    public void setFrame(GUIFrame frame) {
        this.frame = frame;
    }

    /**
     * Load the detailed billing into the fields.
     *
     * @param transactionNumber the transaction number of the billing instance
     *                          to show in detail.
     */
    public void loadPage(String transactionNumber) {
        int transactionNumb;
        try {
            transactionNumb = Integer.parseInt(transactionNumber);
        } catch (NumberFormatException e) {
            JOptionPane.showMessageDialog(this,
                    "An error has occoured.\n No valid transaction number was"
                    + " found.");
            return;
        }

        ArrayList<String> data = frame.bManager.getDetailedBilling(
                transactionNumb);
        if (data.isEmpty()) {
            JOptionPane.showMessageDialog(this,
                    "An error has occoured.\n No valid billing instance was"
                    + " found.");
            return;
        }

        textTransactionNumber.setText(data.get(0));
        textChargingStart.setText(data.get(1));
        textChargingEnd.setText(data.get(2));
        textRecieved.setText(data.get(3));
        textBillingAmount.setText(data.get(4));
        textBillingRate.setText(data.get(5));
        textkWhBilled.setText(data.get(6));
        textNewBalance.setText(data.get(7));
        textBillingAddress.setText(data.get(8));
        textBillingZip.setText(data.get(9));
    }

    /**
     * Reset fields.
     */
    private void resetPage() {
        textTransactionNumber.setText("");
        textChargingStart.setText("");
        textChargingEnd.setText("");
        textRecieved.setText("");
        textBillingAmount.setText("");
        textBillingRate.setText("");
        textkWhBilled.setText("");
        textNewBalance.setText("");
        textBillingAddress.setText("");
        textBillingZip.setText("");
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        labBillingDetails = new javax.swing.JLabel();
        labInformation = new javax.swing.JLabel();
        btnBack = new javax.swing.JButton();
        labDKK1 = new javax.swing.JLabel();
        textChargingStart = new javax.swing.JTextField();
        labBillingRate = new javax.swing.JLabel();
        labChargingStart = new javax.swing.JLabel();
        textBillingRate = new javax.swing.JTextField();
        labDKKkWh = new javax.swing.JLabel();
        labChargingEnd = new javax.swing.JLabel();
        labkWhBilled = new javax.swing.JLabel();
        textChargingEnd = new javax.swing.JTextField();
        textkWhBilled = new javax.swing.JTextField();
        labRecieved = new javax.swing.JLabel();
        labkWh = new javax.swing.JLabel();
        textTransactionNumber = new javax.swing.JTextField();
        labTransactionNumber = new javax.swing.JLabel();
        textBillingZip = new javax.swing.JTextField();
        labBillingZip = new javax.swing.JLabel();
        textBillingAddress = new javax.swing.JTextField();
        labDKK2 = new javax.swing.JLabel();
        labBillingAddress = new javax.swing.JLabel();
        labNewBalance = new javax.swing.JLabel();
        textNewBalance = new javax.swing.JTextField();
        textRecieved = new javax.swing.JTextField();
        textBillingAmount = new javax.swing.JTextField();
        labBillingAmount = new javax.swing.JLabel();

        setPreferredSize(new java.awt.Dimension(402, 302));

        labBillingDetails.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        labBillingDetails.setText("Detailed billing overview");

        labInformation.setText("Below you can see a detailed overview over a selected billing instance.");

        btnBack.setText("Back");
        btnBack.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBackActionPerformed(evt);
            }
        });

        labDKK1.setText("DKK");

        textChargingStart.setEditable(false);
        textChargingStart.setText(" ");

        labBillingRate.setFont(new java.awt.Font("Dialog", 1, 11)); // NOI18N
        labBillingRate.setText("Billing rate");

        labChargingStart.setFont(new java.awt.Font("Dialog", 1, 11)); // NOI18N
        labChargingStart.setText("Start charging time");

        textBillingRate.setEditable(false);
        textBillingRate.setText(" ");

        labDKKkWh.setText("DKK / kWh");

        labChargingEnd.setFont(new java.awt.Font("Dialog", 1, 11)); // NOI18N
        labChargingEnd.setText("End charging time");

        labkWhBilled.setFont(new java.awt.Font("Dialog", 1, 11)); // NOI18N
        labkWhBilled.setText("Wh billed");

        textChargingEnd.setEditable(false);
        textChargingEnd.setText(" ");

        textkWhBilled.setEditable(false);
        textkWhBilled.setText("  ");

        labRecieved.setFont(new java.awt.Font("Dialog", 1, 11)); // NOI18N
        labRecieved.setText("Recieved on server at");

        labkWh.setText("Wh");

        textTransactionNumber.setEditable(false);
        textTransactionNumber.setText(" ");

        labTransactionNumber.setFont(new java.awt.Font("Dialog", 1, 11)); // NOI18N
        labTransactionNumber.setText("Transaction number");

        textBillingZip.setEditable(false);
        textBillingZip.setText(" ");

        labBillingZip.setFont(new java.awt.Font("Dialog", 1, 11)); // NOI18N
        labBillingZip.setText("Billing zipcode");

        textBillingAddress.setEditable(false);
        textBillingAddress.setText(" ");

        labDKK2.setText("DKK");

        labBillingAddress.setFont(new java.awt.Font("Dialog", 1, 11)); // NOI18N
        labBillingAddress.setText("Billing address");

        labNewBalance.setFont(new java.awt.Font("Dialog", 1, 11)); // NOI18N
        labNewBalance.setText("New balance");

        textNewBalance.setEditable(false);
        textNewBalance.setText("  ");

        textRecieved.setEditable(false);

        textBillingAmount.setEditable(false);
        textBillingAmount.setText(" ");

        labBillingAmount.setFont(new java.awt.Font("Dialog", 1, 11)); // NOI18N
        labBillingAmount.setText("Amount billed");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(37, 37, 37)
                        .addComponent(btnBack))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(labBillingAmount, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(textBillingAmount)
                                        .addComponent(labBillingRate)
                                        .addComponent(labkWhBilled)
                                        .addComponent(labNewBalance, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(textBillingRate)
                                        .addComponent(textkWhBilled, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(textNewBalance, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(labDKK2)
                                        .addComponent(labkWh)
                                        .addComponent(labDKKkWh)
                                        .addComponent(labDKK1)))
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(textBillingZip, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(labBillingZip, javax.swing.GroupLayout.Alignment.LEADING)))
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(labBillingDetails)
                                .addComponent(labInformation)))))
                .addContainerGap(108, Short.MAX_VALUE))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(36, 36, 36)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(textTransactionNumber)
                        .addComponent(labTransactionNumber, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(textChargingStart)
                        .addComponent(labChargingStart)
                        .addComponent(labChargingEnd)
                        .addComponent(labRecieved, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(labBillingAddress)
                        .addComponent(textRecieved)
                        .addComponent(textBillingAddress)
                        .addComponent(textChargingEnd))
                    .addGap(301, 301, 301)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(labBillingDetails)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(labInformation, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(labBillingAmount)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textBillingAmount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labDKK1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(labBillingRate)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textBillingRate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labDKKkWh))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(labkWhBilled)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textkWhBilled, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labkWh))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(labNewBalance)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textNewBalance, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labDKK2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(labBillingZip)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(textBillingZip, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(14, 14, 14)
                .addComponent(btnBack)
                .addContainerGap())
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(79, 79, 79)
                    .addComponent(labTransactionNumber)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(textTransactionNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(labChargingStart)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(textChargingStart, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(labChargingEnd)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(textChargingEnd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(labRecieved)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(textRecieved, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(labBillingAddress)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(textBillingAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(49, Short.MAX_VALUE)))
        );
    }// </editor-fold>//GEN-END:initComponents

    /**
     * Change to administrator's transaction history panel.
     * @param evt ActionEvent
     */
    private void btnBackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBackActionPerformed
        resetPage();
        frame.changePanel("card18");
    }//GEN-LAST:event_btnBackActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnBack;
    private javax.swing.JLabel labBillingAddress;
    private javax.swing.JLabel labBillingAmount;
    private javax.swing.JLabel labBillingDetails;
    private javax.swing.JLabel labBillingRate;
    private javax.swing.JLabel labBillingZip;
    private javax.swing.JLabel labChargingEnd;
    private javax.swing.JLabel labChargingStart;
    private javax.swing.JLabel labDKK1;
    private javax.swing.JLabel labDKK2;
    private javax.swing.JLabel labDKKkWh;
    private javax.swing.JLabel labInformation;
    private javax.swing.JLabel labNewBalance;
    private javax.swing.JLabel labRecieved;
    private javax.swing.JLabel labTransactionNumber;
    private javax.swing.JLabel labkWh;
    private javax.swing.JLabel labkWhBilled;
    private javax.swing.JTextField textBillingAddress;
    private javax.swing.JTextField textBillingAmount;
    private javax.swing.JTextField textBillingRate;
    private javax.swing.JTextField textBillingZip;
    private javax.swing.JTextField textChargingEnd;
    private javax.swing.JTextField textChargingStart;
    private javax.swing.JTextField textNewBalance;
    private javax.swing.JTextField textRecieved;
    private javax.swing.JTextField textTransactionNumber;
    private javax.swing.JTextField textkWhBilled;
    // End of variables declaration//GEN-END:variables
}
